import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()

/* 3-12 */
/* 1、封装全局路径: */
/* 公司 */
// let baseUrl = "http://192.168.31.217:8080/emos-wx-api/"
/* 家里 */
let baseUrl = "http://192.168.1.30:8080/emos-wx-api/"

/* 工作流项目地址 */
let workflow = "http://192.168.219.129:9090/emos-workflow"
/* 慕课网授权字符串 */
Vue.prototype.code = "A55DCF455C66950E"

/* 腾讯云TRTC服务 */
Vue.prototype.tencent = {
	trtc: {
		appid: "1400715216"
	}
}

Vue.prototype.url = {
	/* 注册 */
	register: baseUrl + "/user/register",
	/* 登录 */
	login: baseUrl + "/user/login",
	/* 人脸识别路径 */
	checkin: baseUrl + "/checkin/checkin",
	createFaceModel: baseUrl + "/checkin/createFaceModel",
	validCanCheckIn: baseUrl + "/checkin/validCanCheckIn",
	/* 查询用户当日签到数据 */
	searchTodayCheckin: baseUrl + "/checkin/searchTodayCheckin",
	/* 查询用户的概要信息 */
	searchUserSummary: baseUrl + "/user/searchUserSummary",
	/* 查询当月考勤数据 */
	searchMonthCheckin: baseUrl + "/checkin/searchMonthCheckin",
	/* 消息提示 */
	refreshMessage: baseUrl + "/message/refreshMessage",
	/* 加载用户分页数据 */
	searchMessageByPage: baseUrl + "/message/searchMessageByPage",
	/* 根据id查询消息记录 */
	searchMessageById: baseUrl + "/message/searchMessageById",
	/* 将未读消息修改为已读状态 */
	updateUnreadMessage: baseUrl + "/message/updateUnreadMessage",
	/* 删除消息 */
	deleteMessageRefById: baseUrl + "/message/deleteMessageRefById",
	/* 会议列表分页 */
	searchMyMeetingListByPage: baseUrl + "/meeting/searchMyMeetingListByPage",
	/* 会议成员列表 */
	searchUserGroupByDept: baseUrl + "/user/searchUserGroupByDept",
	/* 选择会议列表参会人 */
	searchMembers: baseUrl + "/user/searchMembers",
	/* 保存会议 */
	insertMeeting: baseUrl + "/meeting/insertMeeting",
	/* 查询会议详情 */
	searchMeetingById: baseUrl + "/meeting/searchMeetingById",
	/* 修改会议记录 */
	updateMeetingInfo: baseUrl + "/meeting/updateMeetingInfo",
	/* 删除会议 */
	deleteMeetingById: baseUrl + "/meeting/deleteMeetingById",

	/* 请求工作流 */
	searchUserTaskListByPage: workflow + "/workflow/searchUserTaskListByPage",
	/* 审批会议 */
	approvalMeeting: workflow + "/workflow/approvalMeeting",
	/* 查询发起人与审批人的信息 */
	selectUserPhotoAndName: baseUrl + "/user/selectUserPhotoAndName",
	/* 根据用户id获取签名信息 */
	genUserSig: baseUrl + "/user/genUserSig",
	/* 根据UUID获取视频会议房间号 */
	searchRoomIdByUUID: baseUrl + "/meeting/searchRoomIdByUUID",
	/* 显示日历数据 */
	searchUserMeetingInMonth:baseUrl+"/meeting/searchUserMeetingInMonth"
}

/* 检查用户权限 */
Vue.prototype.checkPermission = function(perms) {
	let permission = uni.getStorageSync("permission")
	let result = false;
	for (let one of perms) {
		if (permission.indexOf(one) != -1) {
			result = true;
			break;
		}
	}
	return result;
}



/* 2、封装Ajax */
Vue.prototype.ajax = function(url, method, data, fun) {
	uni.request({
		"url": url,
		"method": method,
		"header": {
			token: uni.getStorageSync('token')
		},
		"data": data,
		success: function(resp) {
			if (resp.statusCode == 401) {
				uni.redirectTo({
					url: '../login/login'
				});
			} else if (resp.statusCode == 200 && resp.data.code == 200) {
				let data = resp.data
				if (data.hasOwnProperty("token")) {
					console.log(resp.data)
					let token = data.token
					uni.setStorageSync("token", token)
				}
				fun(resp)
			} else {
				uni.showToast({
					icon: 'none',
					title: resp.data
				});
			}
		}
	});
}
/* 封装日期格式化函数 */
Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}


Vue.prototype.checkNull = function(data, name) {
	if (data == null) {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}
Vue.prototype.checkBlank = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}

Vue.prototype.checkValidName = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^[\u4e00-\u9fa5]{2,15}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}

Vue.prototype.checkValidTel = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^1[0-9]{10}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}

Vue.prototype.checkValidEmail = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}

Vue.prototype.checkValidStartAndEnd = function(start, end) {
	let d1 = new Date("2000/01/01 " + start + ":00");
	let d2 = new Date("2000/01/01 " + end + ":00");
	if (d2.getTime() <= d1.getTime()) {
		uni.showToast({
			icon: "none",
			title: "结束时间必须大于开始时间"
		})
		return true
	}
	return false
}
